'''
窗口形式：选择存储照片路径，点击开始，就开始拍照，点击结束，就停止拍照
'''
from tkinter import *
from tkinter.filedialog import askdirectory
from camera import *

def select_path():
    path_ = askdirectory() # 返回文件夹路径
    path.set(path_)

def camera_start():
    if path.get(): # 获取Entry路径
        global  camera
        camera = CameraCapture(path.get())
        print('start capture image')
        camera.run()
    else:
        messagebox.showerror(title="错误提示", message="请先设定照片存放路径")



def camera_end():
    print('stop capture image')
    camera.stop()


if __name__ == "__main__":
    master = Tk()
    path = StringVar()
    master.geometry('300x80') # 设置窗口大小，长X宽
    master.title('Script') # 设置窗口标题

    Label(master,text='目标路径:').grid(row=0,column=0)
    Entry(master,textvariable=path).grid(row=0,column=1)
    Button(master,text='路径选择',command=select_path).grid(row=0,column=2)  # 路径选择，填到上面的Entry中
    Button(master,text="开始",command=camera_start).grid(row=2,column=0)
    Button(master,text="结束",command=camera_end).grid(row=2,column=1)
    mainloop()
